package ink.chow.jdbc.sharding.ctrl;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import ink.chow.jdbc.sharding.dto.DtoResult;
import ink.chow.jdbc.sharding.entity.CustomerTrack;
import ink.chow.jdbc.sharding.service.CustomerTrackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api("customer track")
public class CustomerTrackController {
	@Autowired
	private CustomerTrackService customerTrackService;
	@Autowired
	private DataSource dataSource;
	
	@RequestMapping(value = "/save", method= RequestMethod.POST)
	@ApiOperation("新建")
	public DtoResult<String> save(@RequestBody CustomerTrack customerTrack) {
		customerTrackService.save(customerTrack);
		return new DtoResult<>("200", "ok", "ok");
	}
	@RequestMapping(value = "/find", method= RequestMethod.POST)
	@ApiOperation("查询")
	public DtoResult<CustomerTrack> find(String id){
		System.out.println("ds:  "+dataSource.getClass().getName()+"  "+dataSource);
		return new DtoResult<>("200", "ok", customerTrackService.find(id));
	}
	@RequestMapping(value = "/modify/info", method= RequestMethod.POST)
	@ApiOperation("修改")
	public DtoResult<String> modifyInfo(String id, String info){
		customerTrackService.modifyInfo(id, info);
		return new DtoResult<>("200", "ok", "ok");
	}
	
}
